// pages/order_list/index.js

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs: [{
                title: "所有订单",
                count: "25",
            }, {
                title: "待付款",
                count: "15",
            }, {
                title: "待接单",
                count: "3",
            }, {
                title: "待发货",
                count: "2",
            }, {
                title: "已发货",
                count: "6",
            }, {
                title: "待退款",
                count: "1",
            }, {
                title: "待评价",
                count: "2",
            }, {
                title: "待开票",
                count: "1",
            }, {
                title: "交易成功",
                count: "3",
            }, {
                title: "交易关闭",
                count: "1",
            }

        ],
        activeIndex: 1,
        sliderOffset: 0,
        sliderLeft: 0,
        shops_all: [

        ],
        shops_dfk: [{
            id: '1001',
            order_code: '20181016150100101',
            create_date: '2018-10-16 14:51:48',
            shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_2.png',
            shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
            shop_price: '508.00',
            num: '1',
            order_detail: '（含邮费￥8.00）',
            order_status: '10',
            order_user: '杨颖199357',
            order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
        }, {
            id: '1002',
            order_code: '20181016150100102',
            create_date: '2018-10-18 09:51:55',
            shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_3.png',
            shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
            shop_price: '799.00',
            num: '1',
            order_detail: '（包邮）',
            order_status: '10',
            order_user: '赵丽颖',
            order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
        }],
        shops_djd: [{
            id: '1001',
            order_code: '20181016150100101',
            create_date: '2018-10-16 14:51:48',
            shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_2.png',
            shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
            shop_price: '508.00',
            num: '1',
            order_detail: '（含邮费￥8.00）',
            order_status: '20',
            order_user: '杨颖199357',
            order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
        }, {
            id: '1002',
            order_code: '20181016150100102',
            create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_3.png',
            shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
            shop_price: '799.00',
            num: '1',
            order_detail: '（包邮）',
            order_status: '20',
            order_user: '赵丽颖',
            order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
        }, {
            id: '1003',
            order_code: '20181016150100103',
            create_date: '2018-10-18 19:51:55',
            shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_1.png',
            shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
            shop_price: '499.00',
            num: '1',
            order_detail: '（包邮）',
                order_status: '20',
            order_user: '赵丽颖',
            order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
        }],
        shops_dfh: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_4.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '待发货',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1002',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_1.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '待发货',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ],
        shops_yfh: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_2.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '已发货',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1002',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_2.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '已发货',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ],
        shops_dtk: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/jiaochen_1.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '待退款',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1002',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_4.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '待退款',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ], shops_dpj: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_2.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '待评价',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1002',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_1.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '待评价',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ], shops_dkp: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_4.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '待开票',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ], shops_jycg: [
            {
                id: '1001',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_1.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '交易成功',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1002',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_3.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '交易成功',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }, {
                id: '1003',
                order_code: '20181016150100101',
                create_date: '2018-10-16 14:51:48',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_4.png',
                shop_name: '产品标题—加厚A4打印纸100g 200g打印喷墨激光厚合同标书打印',
                shop_price: '508.00',
                num: '1',
                order_detail: '（含邮费￥8.00）',
                order_status: '交易成功',
                order_user: '杨颖199357',
                order_receive_info: '杨颖，15021106426，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ], shops_jygb: [
            {
                id: '1001',
                order_code: '20181016150100102',
                create_date: '2018-10-18 09:51:55',
                shop_url: 'https://tddtest.zcjb.com.cn/img/shop/biaoshu_1.png',
                shop_name: '专业代写工程、货物、服务标书及投标文件内容检查审核服务',
                shop_price: '799.00',
                num: '1',
                order_detail: '（包邮）',
                order_status: '交易关闭',
                order_user: '赵丽颖',
                order_receive_info: '赵丽颖，13801929912，上海上海市浦东新区金桥镇申江路985弄东力新村24栋501'
            }
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        var tabIndex = options.index;
        if (tabIndex){

            console.info("获取选中tab信息，初始化tab的位置")
            
            const query = wx.createSelectorQuery()
            query.select('#tab_' + tabIndex).boundingClientRect(function (res) {
                console.info("当前选中的tab信息 = %o", res)
                let sliderOffset = res.left - 180;
                console.info("sliderOffset===" + sliderOffset)
                that.setData({
                    sliderLeft: sliderOffset
                })
            });
            query.exec();

            this.setData({
                activeIndex: tabIndex
            })
        }

        this.refreshOrderList();
    },
    tabClick: function(e) {

        this.refreshOrderList();

        console.info("e = %e", e);
        var sliderOffset = e.currentTarget.offsetLeft - 150;
        var index = e.currentTarget.dataset.index;
        console.log("event.currentTarget.dataset.index=" + index)
        this.setData({
            sliderLeft: sliderOffset,
            activeIndex: index
        });
        console.log("sliderLeft=" + this.data.sliderLeft)
        
    },
    refreshOrderList: function(){
        var that = this;
        wx.showLoading({
            title: '加载中',
        })
        console.log("请求后台，刷新列表数据")
        setTimeout(function(){
            wx.hideLoading();
            that.stopPullDownRefresh();
        }, 1000)

    },
    onPullDownRefresh() {
        console.log('onPullDownRefresh', new Date())
        this.refreshOrderList();
        //应该在数据加载完后，调用stopPullDownRefresh
    },
    stopPullDownRefresh() {
        wx.stopPullDownRefresh({
            complete(res) {
                wx.hideToast()
                console.log(res, new Date())
            }
        })
    },
    toPriceChange: function(){
        wx.navigateTo({
            url: '/pages/order_price_change/index',
        })
    },
    toOrderClose: function() {
        wx.navigateTo({
            url: '/pages/order_close/index',
        })
    },
    orderReceive: function(){
        wx.showModal({
            title: '确认',
            content: "是否确认接单？",
            success: function(res){
                if(res.confirm){
                    //点击了确定
                    wx.showToast({
                        title: '接单成功',
                    })
                }
            }
        })
    },
    toOrderAddresseeinfoModify:function(){
        wx.navigateTo({
            url: '/pages/order_addresseeinfo_modify/index',
        })
    },
    toOrderDelivery: function () {
        wx.navigateTo({
            url: '/pages/order_delivery/index',
        })
    },
    agreedRefund: function(){
        wx.showModal({
            title: '确认',
            content: "确认同意退款？",
            success: function (res) {
                if (res.confirm) {
                    //点击了确定
                    wx.showToast({
                        title: '退款操作成功',
                    })
                }
            }
        })
    },
    outlineInvoice: function(){
        //线下索取发票
        wx.showModal({
            title: '确认',
            content: "是否确认线下给予发票？",
            success: function (res) {
                if (res.confirm) {
                    //点击了确定
                    wx.showToast({
                        title: '操作成功',
                    })
                }
            }
        })
    },
    toInvoiceDelivery: function () {
        wx.navigateTo({
            url: '/pages/order_invoice_delivery/index',
        })
    }

    

    
    

})